//
// Created by madison on 2022/1/31.
// 29 计算一个数的 n 次方
//

#include <stdio.h>
#include <math.h>

int main() {
    int base, exponent;
    long long result = 1;

    printf("基数: ");
    scanf("%d", &base);

    printf("指数: ");
    scanf("%d", &exponent);

    while (exponent != 0) {
        result *= base;
        --exponent;
    }
    printf("结果：%lld\n\n", result);

    void fun();
    fun();

    void fun1();
    fun1();

    return 0;
}

// 使用 pow() 函数
void fun() {
    double base, exponent, result;

    printf("基数: ");
    scanf("%lf", &base);

    printf("指数: ");
    scanf("%lf", &exponent);

    // 计算结果
    result = pow(base, exponent);

    printf("%.1lf^%.1lf = %.2lf\n\n", base, exponent, result);
}

// 递归
int power(int n1, int n2);

void fun1() {
    int base, powerRaised, result;

    printf("基数: ");
    scanf("%d", &base);

    printf("指数(正整数): ");
    scanf("%d", &powerRaised);

    result = power(base, powerRaised);

    printf("%d^%d = %d\n\n", base, powerRaised, result);
}

int power(int base, int powerRaised) {
    if (powerRaised != 0)
        return (base * power(base, powerRaised - 1));
    else
        return 1;
}